package com.xiaoka.flutter_plugin_gdmap.AMapNavi;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.amap.api.maps.AMapException;
import com.google.gson.Gson;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

/**
 * Copyright (C), 2020 - 2999, Sichuan Xiaoka Technology Co., Ltd.
 *
 * @Description:
 * @Author: lch
 * @Date: 2020/11/12 15:18
 **/
public class AMapNaviPluginFactory extends PlatformViewFactory{

    private final BinaryMessenger mBinaryMessenger;
    private final Activity mActivity;

    public AMapNaviPluginFactory(BinaryMessenger binaryMessenger, Activity activity) {
        super(StandardMessageCodec.INSTANCE);
        mBinaryMessenger = binaryMessenger;
        mActivity = activity;
    }

    @Override
    public PlatformView create(Context context, int viewId, Object object) {

        Gson gson = new Gson();
        AMapNaviBean aMapNaviBean = new AMapNaviBean();
        if (object instanceof String) {
            Log.e("导航~~~~~~~~~~", "create: "+object.toString());
            aMapNaviBean = gson.fromJson(object.toString(), AMapNaviBean.class);
        }
        AMapNaviPluginView aMapNaviPluginView = null;
        try {
            aMapNaviPluginView = new AMapNaviPluginView(mBinaryMessenger,mActivity, viewId, context, aMapNaviBean);
        } catch (AMapException e) {
            e.printStackTrace();
        }
        return aMapNaviPluginView;
    }

}
